package wiki.generic.concretebar;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import wiki.generic.bar.BarLink;
import wiki.generic.bar.SideBar;
import wiki.generic.io.SideBarWriter;
/**
 * 
 * @author <p><strong>JwTeam</strong></p> 
 *
 */
public class ConcreteSideBarWriter implements SideBarWriter{

	@Override
	public void printSideBar(SideBar bar, String path) {
		
		File file=new File(path);
		try {
			BufferedWriter w=new BufferedWriter(new FileWriter(file));
			List<String> cat=bar.getCategories();
			for (int i = 0; i < cat.size(); i++) {
				String categoria=cat.get(i);
				w.write(categoria);
				List<BarLink> links=bar.getMapLinks().get(categoria);
				for (int j = 0; j < links.size(); j++) {
					BarLink link=links.get(j);
					w.write("$$||$$"+link.getLinkName()+"$$||$$"+link.getURL());
				}
				w.write("\n");
			}
			w.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
